package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// OrderShipmentInfo 物流信息
type OrderShipmentInfo struct {
	ID            string  `json:"id" gorm:"column:id;type:uint;size:64;comment:唯一ID;primaryKey"`
	OutTradeNo    string  `gorm:"column:out_trade_no;type:varchar(50);uniqueIndex:uk_out_trade_no;default:null;comment:订单号;" json:"out_trade_no"`
	ExpressFee    float64 `json:"express_fee" gorm:"column:express_fee;type:decimal(10,2);default:0.00;comment:运费"`
	UserName      string  `json:"user_name" gorm:"column:user_name;type:string;size:30;comment:收件人姓名"`
	TelNumber     string  `json:"tel_number" gorm:"column:tel_number;type:string;size:20;comment:收货人手机号"`
	PostalCode    string  `json:"postal_code" gorm:"column:postal_code;type:string;size:255;comment:邮编"`
	ProvinceName  string  `json:"province_name" gorm:"column:province_name;type:string;size:10;comment:国标收货地址第一级地址"`
	CityName      string  `json:"city_name" gorm:"column:city_name;type:string;size:10;comment:国标收货地址第二级地址"`
	CountyName    string  `json:"county_name" gorm:"column:county_name;type:string;size:20;comment:国标收货地址第三级地址"`
	StreetName    string  `json:"street_name" gorm:"column:street_name;type:string;size:20;comment:国标收货地址第四级地址"`
	DetailAddress string  `json:"detail_address" gorm:"column:detail_address;type:string;size:50;comment:详细地址"`
	ExpressCom    string  `json:"express_com" gorm:"column:express_com;type:varchar(50);comment:快递公司"`
	ExpressNum    string  `json:"express_num" gorm:"column:express_num;type:varchar(50);comment:快递号"`
	Salt          string  `json:"salt" gorm:"column:salt;type:varchar(20);comment:签名用随机字符串"`
	CreatedAt     int64   `gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
	UpdatedAt     int64   `gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间" json:"updated_at"`
}

// TableName 表名称
func (m *OrderShipmentInfo) TableName() string {
	return "order_shipment_info"
}

// BeforeCreate 自增id
func (m *OrderShipmentInfo) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &OrderShipmentInfo{})
}
